package com.example.myapplication.Room.room;
import android.content.Context;

import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;

///数据库关联表
@Database(entities =  {Student.class},version = 1,exportSchema = false)
public abstract class StudentDataBase extends RoomDatabase {

    ///暴露StudentDao

    public abstract StudentDao getStudentDao();

    ///单例，返回DB
    private static StudentDataBase INSTANCE;
    public static synchronized StudentDataBase getInstance(Context context){
        if(INSTANCE == null){
            INSTANCE = Room.databaseBuilder(
                    context.getApplicationContext(),
                    StudentDataBase.class,
                    "student_database"
            )
                    //默认异步线程
                    //强制，开启主线程，（仅在测试中用）
//                    .allowMainThreadQueries()
                    .build();
        }

        return INSTANCE;
    }


}
